package com.xuecheng.content.controller;

import com.xuecheng.commons.model.dto.BindTeachplanMediaDto;
import com.xuecheng.commons.model.dto.TeachplanDto;
import com.xuecheng.commons.model.vo.ResponseResult;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 课程计划前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
@RequestMapping("/teachplan")
@Transactional//开启事务
public class TeachplanController {

    @Autowired
    private TeachplanService  teachplanService;

    /*课程计划列表-树形结构
        get    /{courseId}/tree-nodes
            请求参数:courseId
            返回结果R<thvo>
     */

    @GetMapping("/{courseId}/tree-nodes")
    public ResponseResult treeNodes(@PathVariable("courseId") Long courseId){
        //调用Service
        return teachplanService.treeNodes(courseId);
    }

    /*
    * 保存或者更新课程计划
    * post
    * 请求参数:body dto
    * 返回结果r*/

    @PostMapping
    public ResponseResult saveOrUpdate(@RequestBody TeachplanDto dto){
        //调用service
        return teachplanService.saveOrUpdatePlan(dto);
    }


    /*根据id删除课程计划(逻辑删除)
     DELETE     /{id}
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@PathVariable("id")Long id){
       return teachplanService.deleteTeachplan(id);
    }

    /*课程计划绑定媒资
        POST  /media/association
     */
    @PostMapping("/media/association")
    public ResponseResult association(@RequestBody BindTeachplanMediaDto dto){
         return teachplanService.association(dto);
    }
}
